#pragma once
#include <vector>
#include <vulkan/vulkan_core.h>
#include "gfx-struct.h"
#include <array>


class GfxPipeline;
class GfxTexture;

class GfxObject
{
private:
    bool _isOK = false;
    GfxObjectTypeE _type;
    float _color[4];
    bool _isClear = false;
    GfxPipeline *_pipeline;
    int _indexSize;
    GfxTexture *_texture;

    std::vector<VkDescriptorSet> _descriptorSets;
    void _createDescriptorSet();

    
    VkBuffer _vertexBuffer = VK_NULL_HANDLE; // 顶点数据Buffer
    VkBuffer _indexBuffer = VK_NULL_HANDLE;  // 顶点index数据buffer
    VkDeviceMemory _vertexMemory = VK_NULL_HANDLE;
    VkDeviceMemory _indexMemory = VK_NULL_HANDLE;

    std::vector<VkFramebuffer> _swapChainFramebuffers;
    std::vector<VkCommandBuffer> _commandBuffers;
    void _createFramebuffers();

    void _updateDescriptorSet();
    void _cleanupBuffers();
    void _cleanupFramebuffers();

public:
    GfxObject(GfxObjectTypeE type);
    void setVertexs(std::vector<float> points, std::vector<float> colors, std::vector<float> normals, std::vector<float> uvs, std::vector<uint32_t> indices);
    void setPipeline(GfxPipeline *pipeline);
    void setClear(bool clear);
    void setColor(float r, float g, float b, float a);
    void setTexture(GfxTexture *texture);
    void updateRender(uint32_t index);
    VkCommandBuffer getCommandBuffer(uint32_t index);
    void clear();
    void reset();

    ~GfxObject();
};
